﻿// Shader-Based-Image-Processing (SBIP)
// http://code.google.com/p/sbip/
//
// Copyright © Frank Nagl, 2009-2011
// admin@franknagl.de
//
using Microsoft.Xna.Framework.Graphics;

namespace SBIP.Filter
{
    /// <summary>
    /// An iterative voronoi diagram filter.
    /// </summary>
    /// <remarks><para> Generates a voronoi diagram from a black image 
    /// with non-blacked points in iterative steps.</para>
    /// <para>Sample usage:</para>
    /// <code>
    /// Bitmap image = new Bitmap( "BlackWithColoredPoints.jpg" );
    ///  
    /// // Online rendering of images
    /// // create any windows control for rendering in
    /// Form myForm = new Form
    /// {
    ///     Width = 1280,
    ///     Height = 720
    /// };
    /// // starts Processor
    /// Processor processor.Begin( image, myForm );
    /// // create VoronoiDiagram filter
    /// processor.Filter = new VoronoiDiagram( );
    /// // apply the filter
    /// myForm.Show( );
    /// while ( myForm.Created )
    /// {
    ///     processor.Render( );
    ///     Application.DoEvents( );
    /// }
    /// processor.End( );
    /// </code>
    /// 
    /// <para><b>Initial image (with 20 points):</b></para>
    /// <img src="../../BlackWithColoredPoints.jpg" width="500" height="338" />
    /// <para><b>Result image:</b></para>
    /// <img src="../../VoronoiDiagram.jpg" width="500" height="338" />
    /// </remarks>
    public sealed class VoronoiDiagram : BaseFilter
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="VoronoiDiagram"/> class.
        /// </summary>
        public VoronoiDiagram() : base("VoronoiDiagram") { }

        /// <summary>Renders the specified effect.</summary>
        internal override void RenderEffect()
        {
            Technique = "VoronoiDiagram";            
            Texture = RenderEffectToTexture();
            Technique = "Original";
            base.RenderEffect();
        }

        /// <summary>Renders the specified effect into a texture.</summary>
        /// <returns>The rendered texture.</returns>
        internal override Texture2D RenderEffectToTexture()
        {
            Technique = "VoronoiDiagram";
            return base.RenderEffectToTexture();
        }
    }
}
